import { db } from "@/server/db/db";
import redisUtil from "@/lib/redisUtil";
import { User } from "@/types/auth";
import dayjs from 'dayjs'

export default async function Db() {
  console.log("进入了db");
  const users = await db.query.authUser.findMany();
  const userList = users.map(
    (user) =>
      ({
        id: user.id,
        username: user.username,
        nickname: user.nickname,
        createTime: user.createTime
      } satisfies User)
  );
  await redisUtil.set<User[]>("users", userList);
  const redisUsers = await redisUtil.get<User[]>("users");
  return (
    <div>
      {redisUsers!.map((user) => (
        <div key={user.id}>{typeof user.id}:{user.nickname}--------{dayjs(user.createTime).format('YYYY-MM-DD HH:mm')}</div>
      ))}
    </div>
  );
}
